{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "乐学偶得版权所有  公众号：乐学Fintech  主讲人：William LX_LAB教研团队提供技术支持 正版视频： 网易云课堂：乐学偶得"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import win32com.client\n",
    "\n",
    "# 实例化Excel对象（Create a instance of our excel example）\n",
    "LXODExcelApp = win32com.client.Dispatch(\"Excel.Application\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# make the excel visible 让我们看得到excel\n",
    "LXODExcelApp.Visible = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "LXODWorkbook = LXODExcelApp.Workbooks.Open(r\"C:\\Users\\yons\\Desktop\\华东地区BOSS整理的各门店汇总表.xlsm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: 'Comp1', 2: 'Comp2', 3: 'Comp3'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Box_Dict={}\n",
    "\n",
    "for namedRange in LXODWorkbook.Names:\n",
    "    the_index_of_the_range = namedRange.Index\n",
    "    the_name_of_the_range = namedRange.Name\n",
    "    Box_Dict[the_index_of_the_range]= the_name_of_the_range\n",
    "Box_Dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "LXODPPTApp = win32com.client.Dispatch(\"PowerPoint.Application\")\n",
    "LXODPPTApp.Visible = True\n",
    "\n",
    "BOSSPPT = LXODPPTApp.Presentations.Add()   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这个时候，我们自然而然遇到一个问题：跨应用的复制粘贴\n",
    "OLE（Object Linking and Embedding）\n",
    "把所有东西，当作COM对象（Component Object Model）\n",
    "具体由非常多的方法与参数，怎么找？\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for key,value in Box_Dict.items():\n",
    "    PPTSlide = BOSSPPT.Slides.Add(Index = key , Layout = 12)\n",
    "    LXODExcelApp.Range(value).Copy()\n",
    "    \n",
    "    #OLEObject linked\n",
    "    PPTSlide.Shapes.PasteSpecial(DataType = 10 , Link = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import win32com.client\n",
    "\n",
    "# 实例化Excel对象（Create a instance of our excel example）\n",
    "LXODExcelApp = win32com.client.Dispatch(\"Excel.Application\")\n",
    "# make the excel visible 让我们看得到excel\n",
    "LXODExcelApp.Visible = True\n",
    "LXODWorkbook = LXODExcelApp.Workbooks.Open(r\"C:\\Users\\yons\\Desktop\\华东地区BOSS整理的各门店汇总表.xlsm\")\n",
    "Box_Dict={}\n",
    "\n",
    "for namedRange in LXODWorkbook.Names:\n",
    "    the_index_of_the_range = namedRange.Index\n",
    "    the_name_of_the_range = namedRange.Name\n",
    "    Box_Dict[the_index_of_the_range]= the_name_of_the_range\n",
    "    \n",
    "LXODPPTApp = win32com.client.Dispatch(\"PowerPoint.Application\")\n",
    "LXODPPTApp.Visible = True\n",
    "\n",
    "BOSSPPT = LXODPPTApp.Presentations.Add()   \n",
    "for key,value in Box_Dict.items():\n",
    "    PPTSlide = BOSSPPT.Slides.Add(Index = key , Layout = 12)\n",
    "    LXODExcelApp.Range(value).Copy()\n",
    "    \n",
    "    #OLEObject linked\n",
    "    PPTSlide.Shapes.PasteSpecial(DataType = 10 , Link = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
